package com.qf.spring01.service.imlp;


import com.qf.spring01.dao.UserDao;
import com.qf.spring01.entity.User;
import com.qf.spring01.service.UserService;

import java.sql.*;
import java.util.List;

public class UserServiceImlp implements UserService {
    private UserDao userDao;

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public List<User> getAll() {
        return userDao.getAllUser();
    }

    /**
     *
     * @param fromid
     * @param toid
     * @param amout
     */
    @Override
    public void transfer(Integer fromid, Integer toid, Integer amout) {
        User user = userDao.getSelect(fromid);
        Integer amount = user.getAmount();
        int fromAmout = amount - amout;

        int update = userDao.getUpdate(fromid, fromAmout);
        System.out.println(update);

        User user1 = userDao.getSelect(toid);
        Integer amount1 = user1.getAmount();
        int toAmout = amount1+amout;
        userDao.getUpdate(toid,toAmout);

    }
}
